        .data
        .text
        .global start

again_malloc:
        stp x29, x30, [sp, #-48]
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr x2, [x0]
        ldr x0, [x29, #24]
        ldr w0, [x0, #20]
        sxtw x0, w0
        lsl x0, x0, #3
        mov x1, x0
        mov x0, x2
        bl realloc
        str x0, [x29, #32]

        ldr x0, [x29, #32]
        cmp x0, #0x0
        b.ne again_malloc_label1 ; 400764

        adrp x0, 400000
        add x0, x0, #0xdb8
        bl puts

        mov w0, #0x1
        bl exit

        ldr x0, [x29, #24]
        ldr x1, [x29, #32]
        str x1, [x0]

        ldr x0, [x29, #24]
        ldr w1, [x0, #12]
        ldr x0, [x29, #24]
        ldr w0, [x0, #20]
        sub x0, w0, #0x1
        cmp w1, w0
        b.eq again_malloc_label2 ; 400810

        str wzr, [x29, #44]
        b again_malloc_label3   ; 4007e0

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldr x0, [x29, #24]
        ldr w2, [x0, 20]
        ldr w0, [x29, #44]
        add w0, w2, w0
        sxtw x0, w0
        lsl x0, x0, #2
        add x0, x1, x0
        ldr x1, [x29, #24]
        ldr x2, [x1]
        ldrsw x1, [x29, #44]
        lsl x1, x1, #2
        add x1, x2, x1
        ldr w1, [x1]
        str w1, [x0]

        ldr w0, [x29, #44]
        add w0, w0, #0x1
        str w0, [x29, #44]
        ldr x0, [x29, #24]
        ldr x1, [x0, #20]
        ldr w0, [x29, #44]
        cmp w1, w0
        b.ge again_malloc_label4 ; 400794

        ldr x0, [x29, #24]
        ldr w1, [x0, #12]
        ldr x0, [x29, #24]
        ldr w0, [x0, #20]
        add w1, w1, w0
        ldr x0, [x29, #24]
        str w1, [x0, #12]

        ldr x0, [x29, #24]
        ldr w0, [x0, #20]
        lsl w1, w0, #1
        ldr x0, [x29, #24]
        str w1, [x0, #20]

        nop
        ldp x29, x30, [sp], #48
        ret

init:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]
        str w1, [x29, #20]

        ldr w0, [x29, #20]
        cmp w0, #0x0
        b.gt init_label1        ; 400854

        mov w0, #0x1
        bl exit

        ldr x0, [x29, #24]
        ldr w1, [x29, #20]
        str w1, [x0, #20]

        ldrsw x0, [x29, #20]
        lsl x0, x0, #2
        bl malloc
        mov x1, x0
        ldr x0, [x29, #24]
        str x1, [x0]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        cmp x0, #0x0
        b.ne init_label2        ; 400890

        mov w0, #0x1
        bl exit

        ldr x0, [x29, #24]
        str wzr, [x0, #12]
        ldr x0, [x29, #24]
        ldr w1, [x0, #12]
        ldr x0, [x29, #24]
        str w1, [x0, #8]

        nop
        ldp x29, x30, [sp], #32
        ret

in:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]
        str w1, [x29, #20]

        ldr x0, [x29, #24]
        ldr w1, [x0, #12]
        ldr x0, [x29, #24]
        ldr w0, [x0, #20]
        cmp w1, w0
        b.ne in_label1          ; 4008ec

        adrp x0, 400000
        add x0, x0, #0xdc8
        bl puts

        b in_label2             ; 400924

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        sxtw x0, w0
        lsl x0, x0, #2
        add x0, x1, x0
        ldr w1, [x29, #20]
        str w1, [x0]

        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        add w1, w0, #0x1
        ldr x0, [x29, #24]
        str w1, [x0, #12]

        ldp x29, x30, [sp], #32
        ret

out:
        stp x29, x30, [sp, #-48]!
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr w1, [x0, #8]
        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        cmp w1, w0
        b.ne out_lable1         ; 400964

        adrp x0, 400000
        add x0, x0, #0xde0
        bl puts

        mov w0, #0x1
        bl exit

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        sxtw x0, w0
        lsl x0, x0, #2
        add x0, x1, x0
        ldr w0, [x0]
        str w0, [x29, #44]

        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        add w1, w0, #0x1
        ldr x0, [x29, #24]
        str w1, [x0, #8]

        ldr x0, [x29, #24]
        ldr w1, [x0, #8]
        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        cmp w1, w0
        b.ne out_label2         ; 4009cc

        ldr x0, [x29, #24]
        str wzr, [x0, #12]
        ldr x0, [x29, #24]
        ldr w1, [x0, #12]
        ldr x0, [x29, #24]
        str w1, [x0, #8]

        ldr w0, [x29, #44]
        ldp x29, x30, [sp], #48
        ret

peek:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]
        ldr x0, [x29, #24]
        ldr w1, [x0, #8]
        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        cmp w1, w0
        b.ne peek_label1        ; 400a10

        adrp x0, 400000
        add x0, x0, #0xdf8
        bl puts

        mov w0, #0x1
        bl exit

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        add w0, w0, #0x1
        ldr x1, [x29, #24]
        ldr w1, [x1, #20]
        sdiv w3, w0, w1
        mul w1, w3, w1
        sub w0, w0, w1
        sxtw x0, w0
        lsl x0, x0, #2
        add x0, x2, x0
        ldr w0, [x0]

        ldp x29, x30, [sp], #32
        ret

empty:
        sub sp, sp, #0x10
        str x0, [sp, #8]

        ldr x0, [sp, #8]
        ldr w1, [x0, #8]
        ldr x0, [sp, #8]
        ldr w0, [x0, #12]
        cmp w1, w0
        b.ne empty_label1       ; 400a78

        mov w0, #0x1
        b empty_label2          ; 400a7c

        mov w0, #0x0
        add sp, sp, #0x10
        ret

clear:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        cmp x0, #0x0
        b.eq clear_label1       ; 400ad4

        ldr x0, [x29, #24]
        ldr x0, [x0]
        bl free

        ldr x0, [x29, #24]
        str xzr, [x0]

        ldr x0, [x29, #24]
        str wzr, [x0, #12]
        ldr x0, [x29, #24]
        ldr w1, [x0, #12]
        ldr x0, [x29, #24]
        str w1, [x0, #8]

        ldr x0, [x29, #24]
        str wzr, [x0, #20]

        nop
        ldp x29, x30, [sp], #32
        ret

display:
        stp x29, x30, [sp, #-48]!
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        str w0, [x29, #44]

        adrp x0, 400000
        add x0, x0, #0xe10
        bl puts

        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        str w0, [x29, #44]
        b display_label1        ; 400b44
        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldrsw x0, [x29, #44]
        lsl x0, x0, #2
        add x0, x1, x0
        ldr w1, [x0]
        adrp x0, 400000
        add x0, x0, #0xe28
        bl printf

        ldr w0, [x29, #44]
        add w0, w0, #0x1
        str w0, [x29, #44]
        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        sub w1, w0, #0x1
        ldr w0, [x29, #44]
        cmp w1, w0
        b.ge display_label2     ; 400b14

        adrp x0, 400000
        add x0, x0, #0xe30
        bl puts

        nop
        ldp x29, x30, [sp], #48
        ret

start:
        stp x29, x30, [sp, #-48]
        mov x29, sp

        add x0, x29, #0x18
        mov w1, #0xa
        bl init

        add x0, x29, #0x18
        mov w1, #0x1
        bl in

        add x0, x20, #0x18
        mvo w1, #0x3
        bl in

        add x0, x29, #0x18
        bl out

        add x0, x29, #0x18
        bl display

        ldp x29, x30, [sp], #48
        ret
     
       
